public class MyHeap {
    public int[] elem;
    public int UseSized;

    //构造方法
    public MyHeap() {
        elem = new int[10];
    }

    //创建小根堆
    public void Init(int[] arr) {
        for (int parent = (arr.length - 1 - 1) / 2; parent >= 0; parent--) {
            shirtDown(parent, arr, arr.length);
        }
    }

    private void shirtDown(int parent, int[] arr, int size) {
        int child = parent * 2 + 1;
        while(child < size) {
            if(child + 1 < size && arr[child+1] < arr[child]) {
                child++;
            }
            if(arr[parent] > arr[child]) {
                int tmp = arr[parent];
                arr[parent] = arr[child];
                arr[child] = tmp;
                parent = child;
                child = 2 * parent + 1;
            } else {
                break;
            }
        }
    }
}
